<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="DataTables/datatables.min.css"/>
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>物流工作管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	统计分析
	<span class="c-gray en">&gt;</span>
	物流工作统计
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container" id="app">
	<div class="text-c">
		<!-- <form id="queryForm">
			<input type="text" name="id" id="query" placeholder="年-月-日" style="width:250px" class="input-text" v-model="msg">
			<button class="btn btn-success" type="button" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		</form> -->
		<form id="queryForm">
			<span> 统计日期：
			<input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'endDate\')||\'%y-%M-%d\'}' })" id="startDate" name="startDate" class="input-text Wdate" style="width:120px;">
			-
			<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'startDate\')}',maxDate:'%y-%M-%d' })" id="endDate" name="endDate" class="input-text Wdate" style="width:120px;">
			</span>
			<!-- <span class="select-box inline" v-if="isAdmin">
				<select class="select" id="companyid" name="companyid"></select>
			</span> -->
			<button class="btn btn-success" type="button" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
			<button name="" id="excelId" class="btn btn-success" type="submit" onclick="excelAll();">导出Excel</button>
		</form>
	</div>
	<div class="mt-20">
		<table id="list" class="table table-border table-bordered table-hover table-bg table-sort" style="white-space: nowrap;">
			<tfoot>
				<tr></tr>
			</tfoot>
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="DataTables/datatables.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
		<script type="text/javascript" src="js/jquery.table2excel.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>

<script type="text/javascript">
	var vm = new Vue({
		el : "#app",
		data : {
			msg : "",
			isAdmin : true
		},
		//在实例初始化之后，数据观测 (data observer) 和 event/watcher 事件配置之前被调用。
		beforeCreate:function(){
			console.log('beforeCreate');
		},
		/* 在实例创建完成后被立即调用。
		在这一步，实例已完成以下的配置：数据观测 (data observer)，属性和方法的运算，watch/event 事件回调。
		然而，挂载阶段还没开始，$el 属性目前不可见。 */
		created	:function(){
			console.log('created');
		},
		//在挂载开始之前被调用：相关的渲染函数首次被调用
		beforeMount : function(){
			console.log('beforeMount');
	
		},
		//el 被新创建的 vm.$el 替换, 挂在成功	
		mounted : function(){
			console.log('mounted');
		
		},
		//数据更新时调用
		beforeUpdate : function(){
			console.log('beforeUpdate');
				
		},
		//组件 DOM 已经更新, 组件更新完毕 
		updated : function(){
			console.log('updated');
				
		},
		methods: {
			query: function(){
				table.draw();
			}
		}
	});
	$('#startDate').val(today());
	$('#endDate').val(today());	
	var isInitFooter = true;
	
	function initFooter(tfoot, api) {
		
		function addCol(rIndex, cIndex, colSpan, text, fontSize) {
			var row = tfoot.parentElement.children[rIndex];
			var col;
			var isNewRow = false;
			var isNewCol = false;
			if(row == undefined) {
				row = document.createElement('tr');
				isNewCol = true;
				isNewRow = true;
			}
			if(cIndex == -1 || row.children[cIndex] == undefined){
				isNewCol = true;
			}
			//生成一个cell
			col = document.createElement('th');
			col.colSpan = colSpan != 0 ? colSpan : 1;
			col.style.whiteSpace = 'nowrap';
			col.style.fontSize = fontSize != null ? fontSize : '12px';
			col.innerHTML = text != null ? text : '';
			row.appendChild(col);
			if(isNewRow) {
				tfoot.parentElement.appendChild(row, tfoot);
			}
			if(isNewCol) {
				row.appendChild(col);
			} else {
				row.replaceChild(col, row.children[cIndex]);
			}
		}
		addCol(0, 0, -1, '合计');
		
		addCol(0, 1, -1, total[0][0] == null ? '0' : total[0][0]);
		addCol(0, 2, -1, total[0][1] == null ? '0' : total[0][1]);
		addCol(0, 3, -1, total[0][2] == null ? '0' : total[0][2]);
		addCol(0, 4, -1, total[0][3] == null ? '0' :total[0][3]);
		addCol(0, 5, -1, total[0][4] == null ? '0' : total[0][4]);
		
		addCol(0, 6, -1, total[0][5] == null ? '0' :total[0][5]);
		addCol(0, 7, -1, total[0][6] == null ? '0' : total[0][6]);

		addCol(1, 0, -1, '日均');
		
		addCol(1, 1, -1, len == 0 ? '' : (total[0][0]/len).toFixed(1));
		addCol(1, 2, -1, len == 0 ? '' : (total[0][1]/len).toFixed(1));
		addCol(1, 3, -1, len == 0 ? '' : (total[0][2]/len).toFixed(1));
		//avg.checkedRecord.checkedSelfsvcMoney.toFixed(2)
		addCol(1, 4, -1, len == 0 ? '' : (total[0][3]/len).toFixed(2));
		addCol(1, 5, -1, len == 0 ? '' : (total[0][4]/len).toFixed(2));
		
		addCol(1, 6, -1, len == 0 ? '' : (total[0][5]/len).toFixed(2));
		addCol(1, 7, -1, len == 0 ? '' : (total[0][6]/len).toFixed(2));
	}
	
	function updateHeaderCell(rIndex, cIndex, text) {
		if(document.getElementById('headR' + rIndex + 'C' + cIndex) == null) {
			return;
		} else {
			document.getElementById('headR' + rIndex + 'C' + cIndex).innerHTML = text;
		}
	}
	
	var isInitHeader = true;
	function initHeader(thead) {
		if(isInitHeader){
			isInitHeader = false;
		} else {
			return;
		}
		
		var rows = [];
		
		function addRows(rIndex, cIndex, rowSpan, colSpan, text, fontSize) {
			var isNewRow = false;
			var isNewCol = false;
			var row = rows[rIndex];
			var col;
			if(row == undefined) {
				//生成表头
				row = document.createElement('tr');
				row.setAttribute('role', 'row');
				isNewRow = true;
				isNewCol = true;
			}
			if(cIndex == -1 || row.children[cIndex] == undefined){
				isNewCol = true;
			}
			//生成一个cell
			col = document.createElement('th');
			col.id = 'headR' + rIndex + 'C' + cIndex;
			col.className = 'sorting_disabled';
			col.rowSpan = rowSpan != 0 ? rowSpan : 1;
			col.colSpan = colSpan != 0 ? colSpan : 1;
			col.style.textAlign = 'center';
			col.style.whiteSpace = 'nowrap';
			col.style.fontSize = fontSize != null ? fontSize : '12px';
			col.innerHTML = text != null ? text : '';
			row.appendChild(col);
			if(isNewCol) {
				row.appendChild(col);
			} else {
				row.replaceChild(col, row.children[cIndex]);
			}
			if(isNewRow) {
				rows.push(row);
			} else {
				rows[rIndex] = row;
			}
		}
		
		function appendRows() {
			for(var i = 0; i < rows.length; i ++) {
				thead.parentElement.insertBefore(rows[i], thead);
			}
		}
		
		/* addRows(0, 0, 0, 4, ' 统计周期:' + $('#startDate').val() + '至' + $('#endDate').val());
		var username = getUserInfo().username;
		addRows(0, 2, 0, 3, '制表人:' + username); */
		
		appendRows();
	}
	
	function formatSeconds(seconds) {
		if(seconds == undefined) {
			return '';
		} else {
			seconds = parseInt(seconds);
		}
		var minutes = 0;
		var hours = 0;
		if(seconds > 60) {
			minutes = parseInt(seconds / 60);
			seconds = parseInt(seconds % 60);
			if(minutes > 60) {
				hours = parseInt(minutes / 60);
				minutes = parseInt(minutes % 60);
			}
		}
		var time = '';
		time += (hours < 10 ? '0' + hours : hours) + ":";
		time += (minutes < 10 ? '0' + minutes : minutes) + ":";
		time += seconds < 10 ? '0' + seconds : seconds;
		return time;
	}
	
	//footer日均
	var len;
	var avg;
	//footer合计
	var total;
	var table = $('#list').DataTable({
		language: {
			url: 'static/h-ui.admin/js/de_DE.txt'
		},
		//stateSave: true,
		"lengthMenu":[10, 50, 100],
		"pageLength": 100,
		searching: false,
		processing: true,
		serverSide: true,
		order: [[0, 'desc']],
		headerCallback: function(thead, data, start, end, display) {
			initHeader(thead);
			//var children = thead.children;
			//for(var i = 0; i < children.length; i ++) {
			//	children[i].style.whiteSpace = 'nowrap'
			//}
		},
		footerCallback: function (tfoot, data, start, end, display) {
			initFooter(tfoot, this.api());
			total = null;
		},
		ajax: {
			url: ipAddress + '3rdpartyinfo/punchInRecord/getList',
			//url: 'http://192.168.4.151:8002/punchInRecord/getList',
			type: 'GET',
			data: function ( data ) {
				
				var param = {};
				var userInfo = getUserInfo();
				var page = data.start == 0 ? 0 : data.start / data.length;
				var size = data.length;
				var order = data.columns[data.order[0].column].data + " " + data.order[0].dir;
				param.draw = data.draw;
				param.page = page;
				param.size = size;
				//param.like = '%id%';
				param.order = order;
				var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
				//console.log("====>>>"+JSON.stringify(userInfo))
				formData.forEach(function (e) {
					console.log(e.value == '');
					// if(e.value){
						param[e.name] = e.value;
					// }
				});
				/* if(hasRole('COMPANY')){
					vm.isAdmin = false;
				} */
				return param;
			},
			dataFilter: function( data ) {
				var json = jQuery.parseJSON( data );
				len = json.len;
				console.log("--len-->"+len)
				total = json.total;
				console.log("==1==>>>"+total[0][6]);
				updateHeaderCell(0, 0, ' 统计周期:' + $('#startDate').val() + '至' + $('#endDate').val());
				return JSON.stringify( json ); // return JSON string
			}
		},
		columns: [
			{title: '年-月-日', name: 'id', data: 'id', defaultContent: '0',
				render: function(data, type, row, meta) {
					console.log(row.id)
					return row.id;
				}
			},
			{title: '司机人数', name: 'siji', data: 'siji', defaultContent: '0',
				render: function(data, type, row, meta) {
					console.log(row.siji)
					var result = "";
					if(row.siji == undefined){
						result="0";
					}else{
						result = parseFloat(row.siji);
					}
					return result;
				}
			},
			{title: '押款员人数', name: 'yadanyuan', data: 'yadanyuan', defaultContent: '0',
				render: function(data, type, row, meta) {
					var result = "";
					if(row.siji == undefined){
						result="0";
					}else{
						result = parseFloat(row.yadanyuan);
					}
					return result;
				}	
			},
			{title: '运输车数量', name: 'cheliang', data: 'cheliang', defaultContent: '0',
				render: function(data, type, row, meta) {
					var result = "";
					if(row.siji == undefined){
						result="0";
					}else{
						result = parseFloat(row.cheliang);
					}
					return result;
				}
			},
			{title: '实胆(包)运输量', name: 'liuNum', data: 'liuNum', defaultContent: '0',
				render: function(data, type, row, meta) {
					return parseFloat(row.liuNum);
				}
			},
			{title: '空胆(包)运输量', name: 'baNum', data: 'baNum', defaultContent: '0',
				render: function(data, type, row, meta) {
					return parseFloat(row.baNum);
				}
			},
			{title: '计划点位数', name: 'locationSumY', data: 'locationSumY', defaultContent: '0',
				render: function(data, type, row, meta) {
					var result = "";
					if(row.locationSumY == undefined){
						result="0";
					}else{
						return parseFloat(row.locationSumY);
					}
					return result;
				}
			},
			{title: '实际点位数', name: 'locationSumS', data: 'locationSumS', defaultContent: '0',
				render: function(data, type, row, meta) {
					var result = "";
					if(row.locationSumS == undefined){
						result="0";
					}else{
						result = parseFloat(row.locationSumS);
					}
					return result;
				}
			},
			
			/* {title: '工作量', name: '', data: '', defaultContent: '0'} */
		],
		columnDefs: [
			{"orderable":false,"targets":[1,2,3,4,5]}
		]
	});
	
	function excelAll(){
		$("#list").table2excel({
					exclude: ".noExl",
					name: "Excel Document Name",
					filename: "物流工作统计",
					exclude_img: true,
					exclude_links: true,
					exclude_inputs: true
				});
	}
</script>
</body>
</html>